package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FormResourcePersistRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.command.FormResourceFindCmd;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.command.FormResourcePersistCmd;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.command.FormResourceUpdateCmd;
import org.flowable.engine.ManagementService;
import org.flowable.form.engine.impl.persistence.entity.FormResourceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cheng.huaxing
 * @date 2019-02-28
 */
@Service
public class FormResourcePersistRepositoryImpl implements FormResourcePersistRepository {

    @Autowired
    private ManagementService managementService;

    @Override
    public void insert(FormResourceEntity formResourceEntity) {
        managementService.executeCommand(new FormResourcePersistCmd(formResourceEntity));
    }

    @Override
    public FormResourceEntity find(String processInstanceId, String resourceName) {
        return managementService.executeCommand(new FormResourceFindCmd(processInstanceId, resourceName, null));
    }

    @Override
    public FormResourceEntity find(String formResourceId) {
        return managementService.executeCommand(new FormResourceFindCmd(null, null, formResourceId));
    }

    @Override
    public void update(FormResourceEntity resourceEntity) {
        managementService.executeCommand(new FormResourceUpdateCmd(resourceEntity));
    }
}
